package StudyCode.summary.mycollection;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ConvertArrayAsCollection {
	public static <T> Collection<T> asCollection(T[] elements) {
		return newCollection(elements);
	}

	public static <T> Collection<T> newCollection(Collection<T> collection) {
		if (isNotEmpty(collection)) {
			ArrayList<T> arrayList = new ArrayList<T>(collection.size());
			arrayList.addAll(collection);
			return arrayList;
		}

		return new ArrayList<T>();
	}

	public static <T> Collection<T> newCollection(T... elements) {
		return newList(elements);
	}

	public static <T> Boolean isNotEmpty(Collection<T> collection) {
		return !isEmpty(collection);
	}

	public static <T> List<T> newList(T... elements) {
		if (elements != null) {
			ArrayList<T> arrayList = new ArrayList<T>(elements.length);
			arrayList.addAll(Arrays.asList(elements));
			return arrayList;
		}

		return new ArrayList<T>();
	}

	public static <T> Boolean isEmpty(Collection<T> collection) {
		if (collection == null)
			return Boolean.TRUE;

		return collection.isEmpty();
	}

	public static <T> List<T> asList(Collection<T> collection) {
		if (isNotEmpty(collection))
			return new ArrayList<T>(collection);

		return new ArrayList<T>();
	}

	public static <T> List<T> asList(T[] elements) {
		return newList(elements);
	}
}
